import time
import unittest
from selenium import webdriver
from unit_02.Page.Page3 import Page3
from selenium.webdriver.common.by import By
from unit_02.Tools.Tools import Tools
import logging


class TestCase(unittest.TestCase):
    def setUp(self) -> None:
        print('start case')
        # 初始化日志
        Tools().Log()
        self.driver = webdriver.Firefox()
        # 浏览器事件 窗口最大化
        self.driver.maximize_window()


    def tearDown(self) -> None:
        print('end case')
        time.sleep(5)
        self.driver.quit()

    def test_01(self):
        logging.info('sraet test_01')
        po = Page3(self.driver)
        po.login_luoji()
        # 隐式等待
        self.driver.implicitly_wait(5)
        # 悬浮 我的酒仙
        po.xf_wdjx()
        time.sleep(2)
        # 2.点击我的订单
        po.click_order()
        time.sleep(2)
        # 窗口切换
        po.new_window()
        time.sleep(3)
        # 浏览器事件 刷新浏览器
        po.refresh()
        time.sleep(2)
        # 断言 我的订单
        dy = self.driver.find_element(By.XPATH,'/html/body/div[5]/div[1]/em').text
        print('断言:',dy)
        self.assertIn('我的订单',dy)
        time.sleep(2)
        # 3.输入订单号 ####@@@$$$
        po.sr_ddh()
        time.sleep(2)
        # 鼠标双击事件
        po.clicl_double()
        time.sleep(2)
        # 键盘回车事件
        po.enters()
        time.sleep(2)
        logging.info('sraet test_01')


if __name__ == '__main__':
    unittest.main()
    # 第二种方式
    suite = unittest.TestSuite()
    suite.addTest(TestCase('test_001'))
    unittest.TextTestRunner().run(suite)
    suite =unittest.defaultTestLoader.discover(start_dir='./',pattern='TestCase.py')
    unittest.TextTestRunner().run(suite)